<%@page contentType="application/rdf+xml;charset=UTF-8" %><?xml version="1.0" encoding="utf-8"?>
<%@page import="be.destin.skos.core.SkosManager" %><%@page import="be.destin.skos.core.LocalLinkedConcept" %><%@page import="be.destin.skos.core.ConceptIdentifier" %><%@page import="be.destin.skos.html.SkosHtmlManager" %><%@pageimport="be.destin.skos.core.SchemeInterface" %><%@pageimport="be.destin.skos.core.LinkedConcept" %><%@pageimport="be.destin.skos.core.LocalLinkedConcept" %><%@page import="be.destin.skos.core.SchemeFactory" %><%@page import="be.destin.skos.core.SchemeUsage" %><%@page import="be.destin.skos.core.ConceptScheme" %><%@page import="be.destin.skos.core.Notation" %><%@page import="be.destin.skos.core.Concept" %><%@page import="be.destin.skos.core.Term" %><%@pageimport="be.destin.util.Util" %><%@page import="java.util.NavigableSet" %><%@page import="java.util.Map.Entry" %><%@page import="java.util.Map" %><%@page import="java.util.LinkedList" %><%@page import="java.util.TreeMap" %><%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %><%	 
   SkosHtmlManager skosHtmlManager = SkosHtmlManager.getAskosiSessionInstance(request);
   SkosManager skosManager = skosHtmlManager.getSkosManager();
   String language = skosHtmlManager.getLanguage();
   String about = request.getParameter("about");

   String scheme = request.getScheme();             // http
   String serverName = request.getServerName();     // hostname.com
   int serverPort = request.getServerPort();        // 80
   String contextPath = request.getContextPath();   // /mywebapp
   StringBuffer url =  new StringBuffer();
   url.append(scheme).append("://").append(serverName);
   if (serverPort != 80) {
       url.append(":").append(serverPort);
   }
   url.append(contextPath);
   serverName = url.toString();
   boolean aboutConcept = false;
   String aboutScheme = "";
   if (about != null) {
	int pUnder = about.indexOf('_');
	if (pUnder > 0) {
	   aboutConcept = true;
	   aboutScheme = about.substring(0,pUnder);
	} else aboutScheme = about;
    ConceptScheme aScheme = (ConceptScheme)skosManager.getScheme(aboutScheme);
	if (aScheme !=null) {
	  String baseURL = aScheme.toUriNamespace(skosHtmlManager);
      String schemeURI = aScheme.toUriScheme(skosHtmlManager);
%><?xml-stylesheet type="text/xsl" href="skosrdf2html.xslt"?>
<rdf:RDF xmlns="<%=baseURL%>"
     xml:base="<%=schemeURI%>"
     xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:dct="http://purl.org/dc/terms/"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
     xmlns:skos="http://www.w3.org/2004/02/skos/core#"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"<%--
     xmlns:zbwext="http://zbw.eu/namespaces/skos-extensions/"--%>
><%
if (aboutConcept) {
	Concept aConcept = skosManager.getScheme_Concept(about);
	if (aConcept != null) {
		%><%@include file="skos_concept_include.jnc" %><%
	} else {
    %><!--Concept <%=about%> does not exist.--><%
    }
} else {
   if (aScheme == null) {%>
<!--Scheme <%=about%> not loaded.--><%
   } else {
%>    <skos:ConceptScheme rdf:about="<%=schemeURI%>">
<%  if (aScheme.getTitle() != null) {
%><%=aScheme.getTitle().toHtml("        <dc:title xml:lang=\"[lang]\">[value]</dc:title>\r\n")%><%
    }
	if (aScheme.getDescription() != null) {
%><%=aScheme.getDescription().toHtml("        <dc:description xml:lang=\"[lang]\">[value]</dc:description>\r\n")%><%
    }
	LinkedList<String> aList = aScheme.getCreator();
	if (aList != null) {
		for (String aName : aList) {
%>        <dc:creator><%=aName%></dc:creator>
<%
		}
	}
	aList = aScheme.getContributor();
	if (aList != null) {
		for (String aName : aList) {
%>        <dc:contributor><%=aName%></dc:contributor>
<%
		}
	}
	if (aScheme instanceof ConceptScheme) {
			for (ConceptIdentifier aConceptId : aScheme.getHasTopConcept()) {
			    Concept aConcept = aScheme.getConcept(aConceptId.getAbout());
				if (aConcept != null) {
					%>        <skos:hasTopConcept rdf:resource="<%=baseURL%><%=aConcept.getAbout()%>"/>
<%
				}
			}
		} %>        <dct:available><%=aScheme.getLastLoaded().toString()%></dct:available>
    </skos:ConceptScheme>
<%
		if (aScheme instanceof ConceptScheme) {
			for (Concept aConcept : aScheme.getAllConcepts()) {
				if (aConcept != null) {
					%><%@include file="skos_concept_include.jnc" %><%
				}
			}
		}
   }
}%>
</rdf:RDF>
<% } } //if about!=null + if aScheme!=null%>
